package client;

import bean.User;

import exception.ListProductException;
import service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 后台系统
 * 查询所有学生信息的servlet
 */
@WebServlet("/listUser")
public class ListProductServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// 1.创建service层的对象
		UserService userService = new UserService();
		try {// 2.调用service层的查询所有学生的方法
			List<User> ps = userService.listAll();
			// 3.将查询出的所有学生放进request作用域中
			request.setAttribute("ps", ps);
			System.out.println(ps);
			// 4.重定向到list.jsp页面
			request.getRequestDispatcher("/list.jsp").forward(request, response);
			return;
		} catch (ListProductException e) {
			e.printStackTrace();
		}


	}
}
